package com.tianji.promotion.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.promotion.domain.dto.CouponFormDTO;
import com.tianji.promotion.domain.dto.CouponIssueFormDTO;
import com.tianji.promotion.domain.vo.CouponDetailVO;
import com.tianji.promotion.domain.vo.CouponPageVO;
import com.tianji.promotion.domain.vo.CouponScopeVO;
import com.tianji.promotion.domain.vo.CouponVO;
import com.tianji.promotion.query.CouponQuery;
import com.tianji.promotion.service.ICouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.checkerframework.checker.units.qual.A;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 优惠券的规则信息 前端控制器
 * </p>
 *
 * @author lcm
 * @since 2023-08-01
 */
@RestController
@RequestMapping("/coupons")
@Api(tags = "优惠券相关接口")
@RequiredArgsConstructor
public class CouponController {
    private final ICouponService couponService;

    @PostMapping
    @ApiOperation("新增优惠券")
    public void saveCoupon(@ApiParam("前端请求参数") @RequestBody CouponFormDTO couponFormDTO){
        couponService.saveCoupon(couponFormDTO);
    }

    @GetMapping("/page")
    @ApiOperation("分页查询优惠券")
    public PageDTO<CouponPageVO> pageShowCoupon(@ApiParam("优惠券分页参数") CouponQuery query){
        return couponService.pageShowCoupon(query);
    }

    @PutMapping("/{id}/issue")
    @ApiOperation("发放优惠券")
    public void beginIssue(
            @ApiParam("发放优惠券表单参数") @RequestBody @Valid CouponIssueFormDTO dto){
        couponService.beginIssue(dto);
    }

    @PutMapping("/{id}")
    @ApiOperation("修改优惠券")
    public void updateCoupon(@ApiParam("前端请求参数") @RequestBody CouponFormDTO dto){
        couponService.updateCoupon(dto);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除优惠券")
    public void deleteCoupon(@ApiParam("路径参数优惠券id") @PathVariable Long id){
        couponService.deleteCoupon(id);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询优惠券")
    public CouponDetailVO getCouponById(@ApiParam("路径参数优惠券id") @PathVariable Long id){
        return couponService.getCouponById(id);
    }

    @PutMapping("/{id}/pause")
    @ApiOperation("暂停发放")
    public void pauseCoupon(@PathVariable Long id){
        couponService.pauseCoupon(id);
    }

    @GetMapping("/list")
    @ApiOperation("查询正在发放的优惠券")
    public List<CouponVO> queryIssueCoupons(){
        return couponService.queryIssueCoupons();
    }

}
